package org.madgecko.basic.service.impl;

import org.madgecko.basic.dao.iface.IRoleCommandDao;
import org.madgecko.basic.model.Command;
import org.madgecko.basic.model.Role;
import org.madgecko.basic.model.RoleCommand;
import org.madgecko.basic.service.iface.IRoleCommandService;
import org.springframework.stereotype.Service;

import javax.inject.Inject;

@Service
public class RoleCommandService implements IRoleCommandService {

	@Inject
	private IRoleCommandDao roleCommandDao;

	@Override
	public void add(int roleId, int commandId) {
		RoleCommand rc = new RoleCommand();
		Role r = new Role();
		Command c = new Command();
		r.setId(roleId);
		c.setId(commandId);
		rc.setRole(r);
		rc.setCommand(c);
		roleCommandDao.add(rc);
	}

	@Override
	public void deleteByRoleAndCommand(int roleId, int commandId) {
		//TODO 这2种方式为什么不执行,连控制里的sql都没有，但断点进basedao
//		RoleCommand rc = roleCommandDao.loadByRoleAndCommand(roleId, commandId);
//		System.out.println(rc.getId());
//		roleCommandDao.delete(rc);
//		roleCommandDao.delete(rc.getId());
		roleCommandDao.deleteByRoleAndCommand(roleId, commandId);
	}

	@Override
	public void deleteByRole(int roleId) {
		roleCommandDao.deleteByRole(roleId);
	}
}
